﻿using System;
using System.Linq;
using Framework.Attributes;
using Framework.Model;

namespace CharacterModel
{
    [Serializable]
    public class FeatureType : IId
    {
        [Exclude]
        public FeatureTypeEnum FeatureTypeEnum { get; set; }
        public string Name { get; set; }

        public static FeatureTypeEnum FeatureTypeFromLayerType(LayerTypeEnum layerTypeEnum)
        {
            var featureTypeEnum = Enum.GetValues(typeof (FeatureTypeEnum)).Cast<object>()
                .FirstOrDefault(o => layerTypeEnum.ToString().StartsWith(o.ToString()));
            return featureTypeEnum == null
                       ? FeatureTypeEnum.Head
                       : (FeatureTypeEnum) featureTypeEnum;
        }

        public int Id
        {
            get { return (int) FeatureTypeEnum; }
            set { FeatureTypeEnum = (FeatureTypeEnum) value; }
        }
    }
}